package com.likersai.funa.service.impl;

import com.likersai.funa.dao.CustomerDao;
import com.likersai.funa.pojo.dto.param.customer.CustomerQueryParam;
import com.likersai.funa.pojo.dto.req.customer.CustomerReq;
import com.likersai.funa.pojo.entity.Customer;
import com.likersai.funa.pojo.vo.model.Page;
import com.likersai.funa.service.CustomerService;
import com.likersai.funa.util.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 客户表(Customer)表服务实现类
 *
 * @author sun.ye
 * @since 2021-07-13 13:26:21
 */
@Slf4j
@Service("customerService")
public class CustomerServiceImpl implements CustomerService {

    @Resource
    private CustomerDao customerDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Customer queryById(Long id) {

        return this.customerDao.queryById(id);

    }


    @Override
    public Page<Customer>queryPage(CustomerReq req) {

        CustomerQueryParam pageParam = req.toParam();
        PageUtils.setParamFromReq(req.getPage(),pageParam.getPage());
        List<Customer> result = customerDao.queryList(pageParam);
        int recordsCount = customerDao.queryPageCount(pageParam);
        return PageUtils.getPage(result, recordsCount, req.getPage());

    }

    @Override
    public List<Customer> queryList(CustomerReq req) {

        return customerDao.queryList(req.toParam());

    }


}